const testConfig = require("../../build/webpack.config.test.js");
const path=require('path')
process.env.BABEL_ENV = "test";

module.exports = config => {
  config.set({
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: "",
    plugins: [
      "karma-chrome-launcher",
      "karma-mocha",
      "karma-electron",
      "karma-jasmine-html-reporter",
      "karma-webpack",
      "karma-coverage"
    ],
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    // browsers: ["visibleElectron"],
    // customLaunchers: {
    //   visibleElectron: {
    //     base: "Electron",
    //     flags: ["--show"]
    //   }
    // },
    browsers: ['CustomElectron'],

    // Define a custom launcher which inherits from `Electron`
    customLaunchers: {
      CustomElectron: {
        base: 'Electron',
        userDataDir: path.resolve(__dirname + '/.electron'),
        browserWindowOptions: {
          show: true
        },
        require: path.resolve(__dirname , '../../src/main/main.js')
      }
    },
    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ["mocha"],

    // 测试入口文件
    files: ["./index.js"],
  
    singleRun: true,
    // Webpack配置
    webpack: testConfig,
    // Webpack中间件
    webpackMiddleware: {
      noInfo: true
    },

    // list of files / patterns to exclude
    exclude: [],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      "./index.js": ["webpack","coverage"]
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    //测试覆盖率报告
    reporters: ["progress"],
    // reporters: ["progress","coverage"],
    // coverageReporter: {
    //   type : 'html',
    //   dir : 'coverage/'
    // },
    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  });
};
